package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteNoticeService;
import com.sikaryofficial.system.api.model.notice.NoticePageReq;
import com.sikaryofficial.system.api.model.notice.NoticeResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 日志服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteNoticeFallbackFactory implements FallbackFactory<RemoteNoticeService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteNoticeFallbackFactory.class);

    @Override
    public RemoteNoticeService create(Throwable throwable) {
        log.error("公告服务调用失败:{}", throwable.getMessage());
        return new RemoteNoticeService() {

            @Override
            public R<List<NoticeResp>> listUserNotice(NoticePageReq req) {
                return R.fail(new ArrayList<>(), "notice query error:" + throwable.getMessage());
            }
        };

    }
}
